_unuran_pxd = [
  fs.copyfile('__init__.py'),
  fs.copyfile('unuran.pxd'),
]

unuran_sources = [
  '../../_lib/unuran/unuran/src/distr/cemp.c',
  '../../_lib/unuran/unuran/src/distr/condi.c',
  '../../_lib/unuran/unuran/src/distr/cont.c',
  '../../_lib/unuran/unuran/src/distr/corder.c',
  '../../_lib/unuran/unuran/src/distr/cvec.c',
  '../../_lib/unuran/unuran/src/distr/cvemp.c',
  '../../_lib/unuran/unuran/src/distr/cxtrans.c',
  '../../_lib/unuran/unuran/src/distr/discr.c',
  '../../_lib/unuran/unuran/src/distr/distr.c',
  '../../_lib/unuran/unuran/src/distr/distr_info.c',
  '../../_lib/unuran/unuran/src/distr/matr.c',
  '../../_lib/unuran/unuran/src/distributions/c_F.c',
  '../../_lib/unuran/unuran/src/distributions/c_beta.c',
  '../../_lib/unuran/unuran/src/distributions/c_beta_gen.c',
  '../../_lib/unuran/unuran/src/distributions/c_burr.c',
  '../../_lib/unuran/unuran/src/distributions/c_cauchy.c',
  '../../_lib/unuran/unuran/src/distributions/c_chi.c',
  '../../_lib/unuran/unuran/src/distributions/c_chi_gen.c',
  '../../_lib/unuran/unuran/src/distributions/c_chisquare.c',
  '../../_lib/unuran/unuran/src/distributions/c_exponential.c',
  '../../_lib/unuran/unuran/src/distributions/c_exponential_gen.c',
  '../../_lib/unuran/unuran/src/distributions/c_extremeI.c',
  '../../_lib/unuran/unuran/src/distributions/c_extremeII.c',
  '../../_lib/unuran/unuran/src/distributions/c_gamma.c',
  '../../_lib/unuran/unuran/src/distributions/c_gamma_gen.c',
  '../../_lib/unuran/unuran/src/distributions/c_ghyp.c',
  '../../_lib/unuran/unuran/src/distributions/c_gig.c',
  '../../_lib/unuran/unuran/src/distributions/c_gig2.c',
  '../../_lib/unuran/unuran/src/distributions/c_gig_gen.c',
  '../../_lib/unuran/unuran/src/distributions/c_hyperbolic.c',
  '../../_lib/unuran/unuran/src/distributions/c_ig.c',
  '../../_lib/unuran/unuran/src/distributions/c_laplace.c',
  '../../_lib/unuran/unuran/src/distributions/c_logistic.c',
  '../../_lib/unuran/unuran/src/distributions/c_lognormal.c',
  '../../_lib/unuran/unuran/src/distributions/c_lomax.c',
  '../../_lib/unuran/unuran/src/distributions/c_meixner.c',
  '../../_lib/unuran/unuran/src/distributions/c_normal.c',
  '../../_lib/unuran/unuran/src/distributions/c_normal_gen.c',
  '../../_lib/unuran/unuran/src/distributions/c_pareto.c',
  '../../_lib/unuran/unuran/src/distributions/c_powerexponential.c',
  '../../_lib/unuran/unuran/src/distributions/c_powerexponential_gen.c',
  '../../_lib/unuran/unuran/src/distributions/c_rayleigh.c',
  '../../_lib/unuran/unuran/src/distributions/c_slash.c',
  '../../_lib/unuran/unuran/src/distributions/c_slash_gen.c',
  '../../_lib/unuran/unuran/src/distributions/c_student.c',
  '../../_lib/unuran/unuran/src/distributions/c_student_gen.c',
  '../../_lib/unuran/unuran/src/distributions/c_triangular.c',
  '../../_lib/unuran/unuran/src/distributions/c_uniform.c',
  '../../_lib/unuran/unuran/src/distributions/c_vg.c',
  '../../_lib/unuran/unuran/src/distributions/c_weibull.c',
  '../../_lib/unuran/unuran/src/distributions/d_binomial.c',
  '../../_lib/unuran/unuran/src/distributions/d_binomial_gen.c',
  '../../_lib/unuran/unuran/src/distributions/d_geometric.c',
  '../../_lib/unuran/unuran/src/distributions/d_hypergeometric.c',
  '../../_lib/unuran/unuran/src/distributions/d_hypergeometric_gen.c',
  '../../_lib/unuran/unuran/src/distributions/d_logarithmic.c',
  '../../_lib/unuran/unuran/src/distributions/d_logarithmic_gen.c',
  '../../_lib/unuran/unuran/src/distributions/d_negativebinomial.c',
  '../../_lib/unuran/unuran/src/distributions/d_poisson.c',
  '../../_lib/unuran/unuran/src/distributions/d_poisson_gen.c',
  '../../_lib/unuran/unuran/src/distributions/d_zipf.c',
  '../../_lib/unuran/unuran/src/distributions/d_zipf_gen.c',
  '../../_lib/unuran/unuran/src/distributions/m_correlation.c',
  '../../_lib/unuran/unuran/src/distributions/vc_copula.c',
  '../../_lib/unuran/unuran/src/distributions/vc_multicauchy.c',
  '../../_lib/unuran/unuran/src/distributions/vc_multiexponential.c',
  '../../_lib/unuran/unuran/src/distributions/vc_multinormal.c',
  '../../_lib/unuran/unuran/src/distributions/vc_multinormal_gen.c',
  '../../_lib/unuran/unuran/src/distributions/vc_multistudent.c',
  '../../_lib/unuran/unuran/src/methods/arou.c',
  '../../_lib/unuran/unuran/src/methods/ars.c',
  '../../_lib/unuran/unuran/src/methods/auto.c',
  '../../_lib/unuran/unuran/src/methods/cext.c',
  '../../_lib/unuran/unuran/src/methods/cstd.c',
  '../../_lib/unuran/unuran/src/methods/dari.c',
  '../../_lib/unuran/unuran/src/methods/dau.c',
  '../../_lib/unuran/unuran/src/methods/dext.c',
  '../../_lib/unuran/unuran/src/methods/dgt.c',
  '../../_lib/unuran/unuran/src/methods/dsrou.c',
  '../../_lib/unuran/unuran/src/methods/dss.c',
  '../../_lib/unuran/unuran/src/methods/dstd.c',
  '../../_lib/unuran/unuran/src/methods/empk.c',
  '../../_lib/unuran/unuran/src/methods/empl.c',
  '../../_lib/unuran/unuran/src/methods/gibbs.c',
  '../../_lib/unuran/unuran/src/methods/hinv.c',
  '../../_lib/unuran/unuran/src/methods/hist.c',
  '../../_lib/unuran/unuran/src/methods/hitro.c',
  '../../_lib/unuran/unuran/src/methods/hrb.c',
  '../../_lib/unuran/unuran/src/methods/hrd.c',
  '../../_lib/unuran/unuran/src/methods/hri.c',
  '../../_lib/unuran/unuran/src/methods/itdr.c',
  '../../_lib/unuran/unuran/src/methods/mcorr.c',
  '../../_lib/unuran/unuran/src/methods/mixt.c',
  '../../_lib/unuran/unuran/src/methods/mvstd.c',
  '../../_lib/unuran/unuran/src/methods/mvtdr.c',
  '../../_lib/unuran/unuran/src/methods/ninv.c',
  '../../_lib/unuran/unuran/src/methods/norta.c',
  '../../_lib/unuran/unuran/src/methods/nrou.c',
  '../../_lib/unuran/unuran/src/methods/pinv.c',
  '../../_lib/unuran/unuran/src/methods/srou.c',
  '../../_lib/unuran/unuran/src/methods/ssr.c',
  '../../_lib/unuran/unuran/src/methods/tabl.c',
  '../../_lib/unuran/unuran/src/methods/tdr.c',
  '../../_lib/unuran/unuran/src/methods/unif.c',
  '../../_lib/unuran/unuran/src/methods/utdr.c',
  '../../_lib/unuran/unuran/src/methods/vempk.c',
  '../../_lib/unuran/unuran/src/methods/vnrou.c',
  '../../_lib/unuran/unuran/src/methods/x_gen.c',
  '../../_lib/unuran/unuran/src/parser/functparser.c',
  '../../_lib/unuran/unuran/src/parser/parser.c',
  '../../_lib/unuran/unuran/src/parser/stringparser.c',
  '../../_lib/unuran/unuran/src/specfunct/bessel_asympt.c',
  '../../_lib/unuran/unuran/src/specfunct/cephes_gamma.c',
  '../../_lib/unuran/unuran/src/specfunct/cephes_igam.c',
  '../../_lib/unuran/unuran/src/specfunct/cephes_incbet.c',
  '../../_lib/unuran/unuran/src/specfunct/cephes_ndtr.c',
  '../../_lib/unuran/unuran/src/specfunct/cephes_ndtri.c',
  '../../_lib/unuran/unuran/src/specfunct/cephes_polevl.c',
  '../../_lib/unuran/unuran/src/specfunct/cgamma.c',
  '../../_lib/unuran/unuran/src/specfunct/hypot.c',
  '../../_lib/unuran/unuran/src/tests/chi2test.c',
  '../../_lib/unuran/unuran/src/tests/correlation.c',
  '../../_lib/unuran/unuran/src/tests/countpdf.c',
  '../../_lib/unuran/unuran/src/tests/counturn.c',
  '../../_lib/unuran/unuran/src/tests/inverror.c',
  '../../_lib/unuran/unuran/src/tests/moments.c',
  '../../_lib/unuran/unuran/src/tests/printsample.c',
  '../../_lib/unuran/unuran/src/tests/quantiles.c',
  '../../_lib/unuran/unuran/src/tests/tests.c',
  '../../_lib/unuran/unuran/src/tests/timing.c',
  '../../_lib/unuran/unuran/src/urng/urng.c',
  '../../_lib/unuran/unuran/src/urng/urng_default.c',
  '../../_lib/unuran/unuran/src/urng/urng_set.c',
  '../../_lib/unuran/unuran/src/urng/urng_unuran.c',
  '../../_lib/unuran/unuran/src/utils/debug.c',
  '../../_lib/unuran/unuran/src/utils/eigensystem.c',
  '../../_lib/unuran/unuran/src/utils/error.c',
  '../../_lib/unuran/unuran/src/utils/fmax.c',
  '../../_lib/unuran/unuran/src/utils/hooke.c',
  '../../_lib/unuran/unuran/src/utils/lobatto.c',
  '../../_lib/unuran/unuran/src/utils/matrix.c',
  '../../_lib/unuran/unuran/src/utils/mrou_rectangle.c',
  '../../_lib/unuran/unuran/src/utils/slist.c',
  '../../_lib/unuran/unuran/src/utils/stream.c',
  '../../_lib/unuran/unuran/src/utils/string.c',
  '../../_lib/unuran/unuran/src/utils/umalloc.c',
  '../../_lib/unuran/unuran/src/utils/umath.c',
  '../../_lib/unuran/unuran/src/utils/unur_fp.c',
  '../../_lib/unuran/unuran/src/utils/vector.c'
]

unuran_include_dirs = [
  '../../_lib/src',  # for messagestream.h
  '../../_lib/unuran/unuran/src',
  '../../_lib/unuran/unuran/src/distr',
  '../../_lib/unuran/unuran/src/distributions',
  '../../_lib/unuran/unuran/src/methods',
  '../../_lib/unuran/unuran/src/parser',
  '../../_lib/unuran/unuran/src/specfunct',
  '../../_lib/unuran/unuran/src/urng',
  '../../_lib/unuran/unuran/src/utils',
  '../../_lib/unuran/unuran/src/tests'
]

unuran_version = '16:0:0'  # taken from `_lib/unuran/unuran/configure.ac`

unuran_defines = [
  '-DHAVE_ALARM=1',
  '-DHAVE_DECL_ALARM=1',
  '-DHAVE_DECL_HUGE_VAL=1',
  '-DHAVE_DECL_INFINITY=1',
  '-DHAVE_DECL_ISFINITE=1',
  '-DHAVE_DECL_ISINF=1',
  '-DHAVE_DECL_ISNAN=1',
  '-DHAVE_DECL_LOG1P=1',
  '-DHAVE_DECL_SIGNAL=1',
  '-DHAVE_DECL_SNPRINTF=1',
  '-DHAVE_DECL_VSNPRINTF=1',
  '-DHAVE_FLOAT_H=1',
  '-DHAVE_FLOOR=1',
  '-DHAVE_IEEE_COMPARISONS=1',
  '-DHAVE_INTTYPES_H=1',
  '-DHAVE_LIBM=1',
  '-DHAVE_LIMITS_H=1',
  '-DHAVE_POW=1',
  '-DHAVE_SIGNAL=1',
  '-DHAVE_SQRT=1',
  '-DHAVE_STDIO_H=1',
  '-DHAVE_STDINT_H=1',
  '-DHAVE_STDLIB_H=1',
  '-DHAVE_STRCHR=1',
  '-DHAVE_STRING_H=1',
  '-DHAVE_STRTOL=1',
  '-DHAVE_STRTOUL=1',
  '-DLT_OBJDIR=libs/',
  '-DPACKAGE=unuran',
  '-DPACKAGE_BUGREPORT=unuran@statmath.wu.ac.at',
  '-DPACKAGE_NAME=unuran',
  '-DPACKAGE_STRING=unuran ' + unuran_version,
  '-DPACKAGE_TARNAME=unuran',
  '-DPACKAGE_URL=',
  '-DPACKAGE_VERSION=' + unuran_version,
  '-DUNUR_ENABLE_INFO=1',
  '-DVERSION=' + unuran_version,
  '-DHAVE_CONFIG_H=1',
  '-D_ISOC99_SOURCE=1',
  '-DHAVE_DECL_HYPOT=1'
]

# Cython pyx -> c generator with _lib_pxd dependency, because the unuran
# code depends on _lib/_ccallback_c
unuran_cython_gen = generator(cython,
  arguments : cython_args,
  output : '@BASENAME@.c',
  depends : [_cython_tree, _lib_pxd, _stats_pxd, _unuran_pxd]
)

py3.extension_module('unuran_wrapper',
  [
    unuran_cython_gen.process('unuran_wrapper.pyx'),
    unuran_sources
  ],
  c_args: [unuran_defines, cython_c_args],
  include_directories: [unuran_include_dirs],
  dependencies: np_dep,
  link_args: version_link_args,
  install: true,
  subdir: 'scipy/stats/_unuran'
)


py3.install_sources([
    '__init__.py',
    'unuran_wrapper.pyi',
  ],
  subdir: 'scipy/stats/_unuran'
)
